﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DTO;

namespace DAO
{
    public class phong_DAO
    {
        public static DataSet loadthongtinphongvaolist()
        {
            string sql="select map,lp.maloaip,dongia,tenloaip from phong p,loaiphong lp where p.maloaip=lp.maloaip and tinhtrang=false order by map asc";
            DataSet ds=new DataSet();
            ds=dataconnect.laydulieu(sql);
            return ds;
        }
        public static bool kiemtratinhtrangphong(phong_DTO p)
        {
            string sql = "select tinhtrang from phong where tinhtrang=true and map="+p.map+"";
            return dataconnect.xulycaulenh(sql);
        }
        public static DataSet loadphong()
        {
            string sql = "select * from phong order by map asc";
            DataSet ds = new DataSet();
            ds = dataconnect.laydulieu(sql);
            return ds;
        }
        public static DataSet timphong(phong_DTO p)
        {
            string sql=" select * from phong where map="+p.map+"";
            DataSet ds=new DataSet();
            ds=dataconnect.laydulieu(sql);
            return ds;
        }
        public static DataSet automa()
        {
            string sql = "select top 1 map from phong order by map desc";
            DataSet ds = new DataSet();
            ds = dataconnect.laydulieu(sql);
            return ds;
        }
        public static DataSet loadloaiphong()
        {
            string sql = "select * from loaiphong";
            DataSet ds = new DataSet();
            ds = dataconnect.laydulieu(sql);
            return ds;
        }
        public static DataSet thongtinloaiphong()
        {
            string sql = "select * from loaiphong";
            DataSet ds=new DataSet();
            ds = dataconnect.laydulieu(sql);
            return ds;
        }
        public static bool themphong(phong_DTO p)
        {
            string sql = "insert into phong(maloaip,tinhtrang) values ('"+p.maloaip+"',"+p.tinhtrang+")";
            return  dataconnect.xulycaulenh(sql);
        }
        public static bool xoaphong(phong_DTO p)
        {
            string sql = "delete from phong where map="+p.map+"";
            return dataconnect.xulycaulenh(sql);
        }
        public static bool suaphong(phong_DTO p)
        {
            string sql = "update phong set maloaip='"+p.maloaip+"' where map="+p.map+"";
            return dataconnect.xulycaulenh(sql);
        }
    }
}
